package com.ipc.admin.service.gwl.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ipc.admin.service.gwl.service.SecondScreenService;
import com.ipc.common.pojo.bo.gwl.PageAndSearchBo;
import com.ipc.common.pojo.bo.gwl.SecondScreenBo;
import com.ipc.common.pojo.vo.R;
import com.ipc.core.dao.gwl.SecondScreenDao;
import com.ipc.core.entity.gwl.SecondScreen;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (SecondScreen)表服务实现类
 *
 * @author 高万里
 * @since 2023-04-28 14:16:17
 */
@Service("secondScreenService")
public class SecondScreenServiceImpl implements SecondScreenService {

    @Resource
    private SecondScreenDao dao;

    @Override
    public R add(SecondScreen screen) {
        if (dao.getNo(screen.getNo()) != null) {
            return R.fail("此编号已存在！");
        }
        return R.ok(dao.insert(screen));
    }

    @Override
    public R del(int id) {
        if (id < 1) {
            return R.fail("参数错误，删除失败");
        }
        if (dao.deleteById(id) > 0) {
            return R.ok();
        }
        return R.fail("删除失败");
    }

    @Override
    public R update(SecondScreen screen) {
        if (dao.getNo(screen.getNo()) != null) {
            return R.fail("此编号已存在！");
        }
        return R.ok(dao.updateById(screen));
    }

    @Override
    public R selectOne(int id) {
        return R.ok(dao.selectById(id));
    }

    @Override
    public R selectAll(PageAndSearchBo bo) {
        PageHelper.startPage(bo.getPage(), bo.getSize());
        PageInfo<SecondScreenBo> pageInfo = new PageInfo<>(dao.selectAll(bo.getName()));
        return R.ok(pageInfo);
    }

}

